#include "EntitiesContainer.h"

namespace coolpool
{
	EntitiesContainer::EntitiesContainer(const EntitiesPointers & entities)
	{
		initBasicTypesLists(entities);
	}

	void EntitiesContainer::initBasicTypesLists(const EntitiesPointers & entities)
	{
		for (unsigned i = 0; i < entities.size(); ++i)
		{
			// Basics types pointers lists
			this->all_.push_back(entities[i]);
			if (!entities[i]->isStatic())
				this->dynamics_.push_back(static_cast<DynamicEntity *>(entities[i]));
			else
				this->statics_.push_back(entities[i]);
		}
	}

	EntitiesContainer::~EntitiesContainer()
	{
		// Deallocate entities
		EntitiesPointers * ep = this->getAll();
		for (std::vector<Entity *>::iterator i = ep->begin(); i != ep->end(); i++)
			delete (*i);
	}

	DynamicEntitiesPointers * EntitiesContainer::getDynamicEntities()
	{
		return &dynamics_;
	}

	EntitiesPointers * EntitiesContainer::getStaticEntities()
	{
		return &statics_;
	}

	EntitiesPointers * EntitiesContainer::getAll()
	{
		return &all_;
	}
}
